home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / UI101.ZIP / IO / KB / KB_X.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  4KB  |  152 lines

  1. /*************************************************************************
  2.  
  3.     kb_x.c          Keyboard (KB) Subroutines
  4.             for Bywater Software.
  5.  
  6.             Implementation for X Windows System
  7.             Depends on gr_x.c
  8.  
  9.             Copyright (c) 1991, Ted A. Campbell
  10.  
  11.             Bywater Software
  12.             P. O. Box 4023 
  13.             Duke Station 
  14.             Durham, NC  27706
  15.  
  16.             email: tcamp@hercules.acpub.duke.edu
  17.  
  18.     Copyright and Permissions Information:
  19.  
  20.     All U.S. and international copyrights are claimed by the
  21.     author. The author grants permission to use this code
  22.     and software based on it under the following conditions:
  23.     (a) in general, the code and software based upon it may be 
  24.     used by individuals and by non-profit organizations; (b) it
  25.     may also be utilized by governmental agencies in any country,
  26.     with the exception of military agencies; (c) the code and/or
  27.     software based upon it may not be sold for a profit without
  28.     an explicit and specific permission from the author, except
  29.     that a minimal fee may be charged for media on which it is
  30.     copied, and for copying and handling; (d) the code must be 
  31.     distributed in the form in which it has been released by the
  32.     author; and (e) the code and software based upon it may not 
  33.     be used for illegal activities. 
  34.  
  35. **************************************************************************/
  36.  
  37. #include "stdio.h"
  38. #include "kb.h"
  39.  
  40. #ifndef   TRUE
  41. #define   TRUE   1
  42. #define   FALSE   0
  43. #endif
  44.  
  45. #ifndef   ESC
  46. #define   ESC   0x1b
  47. #endif
  48.  
  49. extern int x_keybevent;
  50. extern int x_keypending;
  51.  
  52. /*************************************************************************
  53.  
  54.    FUNCTION:       kb_init()
  55.  
  56.    DESCRIPTION:    This function should perform any initialization
  57.          necessary for the keyboard system.
  58.  
  59.    INPUT:          none.
  60.  
  61.    RETURNS:        none.
  62.  
  63. **************************************************************************/
  64.  
  65. kb_init()
  66.    {
  67.    }
  68.  
  69.  
  70. /*************************************************************************
  71.  
  72.    FUNCTION:       kb_deinit()
  73.  
  74.    DESCRIPTION:    This function should perform any necessary
  75.          deinitialization, that is, return the keyboard
  76.          to its default state when a Simple Software
  77.          program is to be exited.
  78.  
  79.    INPUT:          none.
  80.  
  81.    RETURNS:        none.
  82.  
  83. **************************************************************************/
  84.  
  85. kb_deinit()
  86.    {
  87.    }
  88.  
  89. /*************************************************************************
  90.  
  91.    FUNCTION:       kb_rxstat()
  92.  
  93.    DESCRIPTION:    This function determines whether a character is
  94.          ready from the console.  The function is used
  95.          especially in telecommunications programs,
  96.          where it is necessary to poll the keyboard
  97.          without locking up the program waiting for a
  98.          response.
  99.  
  100.    INPUT:          none.
  101.  
  102.    RETURNS:        The function returns 0 if no character is
  103.          available and 1 if a character is available.
  104.  
  105. **************************************************************************/
  106.  
  107. kb_rxstat()
  108.    {
  109.    if ( x_keybevent == TRUE )
  110.       {
  111.       return TRUE;
  112.       }
  113.    x_pollevent();
  114.    if ( x_keybevent == TRUE )
  115.       {
  116.       return TRUE;
  117.       }
  118.    return FALSE;
  119.    }
  120.  
  121. /*************************************************************************
  122.  
  123.    FUNCTION:       kb_rx()
  124.  
  125.    DESCRIPTION:    This function returns a single character from
  126.          the keyboard.  If a character is not available
  127.          it waits.  The function should be able to
  128.          recognize any special keys, and return the
  129.          appropriate Simple Software KB conventions
  130.          designated for them.
  131.  
  132.    INPUT:          none.
  133.  
  134.    RETURNS:        The function returns the ASCII code for the
  135.          key pressed, or the Simple Software KB convention
  136.          (see kb.h) for a function or other special key.
  137.  
  138. **************************************************************************/
  139.  
  140. kb_rx()
  141.    {
  142.  
  143.    while( x_keybevent == FALSE )
  144.       {
  145.       x_pollevent();
  146.       }
  147.    x_keybevent = FALSE;
  148.    return ( x_keypending );
  149.  
  150.    }
  151.  
  152.